<!DOCTYPE html>
<html>
<script type="text/javascript" src="./js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="./js/jquery.tablesorter.min.js"></script>

<link type="text/css" rel="stylesheet" href="./css/fupan_css.css">
<link type="text/css" rel="stylesheet" href="./css/calendar.css">
<link type="text/css" rel="stylesheet" href="./kpl/com.css">
<link type="text/css" rel="stylesheet" href="./kpl/index.css">
<link type="text/css" rel="stylesheet" href="./kpl/fChart.css">
<link type="text/css" rel="stylesheet" href="./kpl/mpage.css">

<script src="./js/update.js"></script>
<script src="./js/show_message.js"></script>

<script src="./js/kaipanla.js"></script>

<!-- <script src="./kpl/jquery.js"></script> -->
<script src="./kpl/com.js"></script>
<!--分时-->
<script src="./kpl/floatMChart.js"></script>
<!--K线-->
<script src="./kpl/floatKChart.js"></script>
<script src="./kpl/fChart.js"></script>


<script>
    $(document).ready(function () {
        ajaxUrl();
    });
</script>

<script>
    function ajaxUrl() {
        var url = "https://raw.githubusercontent.com/2022xiaohu/2022xiaohu.github.io/main/2021-06-02.csv";
        var htmlobj = $.ajax({ url: url, async: false });
        console.log(htmlobj.responseText);
        codes = setTableCvs(htmlobj.responseText);
        codesRise(codes, htmlobj.responseText, setTableInternet)
    }

</script>

<script>
    //导入并显示CVS数据
    function setTableCvs(data) {
        codes = [];
        var m_html = ""
        const mCode = 1   //代码序列号
        const myArray = data.split("\n");
        // var m_list = myArray
        for (var i_row = 0; i_row < myArray.length; i_row++) {
            const m_list = myArray[i_row].split(",");
            if (i_row % 2 == 0) {
                m_html += "<tr>"
            } else
                m_html += "<tr class=\"cur\">"

            for (var mCount = 0; mCount < m_list.length; mCount++) {
                if (isNumber(m_list[mCount])) {
                    if (m_list[mCount].length == 6)
                        codes.push(m_list[mCount])
                }
                if (m_list[mCount + 1] == "" && m_list[mCount + 2] == "") {
                    m_html += "<td colspan =\"" + (m_list.length - mCount) + "\" >" + m_list[mCount] + "</td>"  //合并行
                    break;
                }
                m_html += "<td>" + m_list[mCount] + "</td>"
            }
            m_html += "</tr>"
        }
        var tb = document.getElementById('table'); //获取表格的dom节点
        tb.innerHTML = m_html
        return codes
    }
</script>
<script>
    //导入并显示CVS数据
    function setTableInternet(dataCvs, dataInternet) {
        var m_html = ""
        const mCode = 1   //代码序列号
        const mPrice = 6   //代码序列号
        const myArray = dataCvs.split("\n");
        var statusNumber = false
        // var m_list = myArray
        for (var i_row = 0; i_row < myArray.length; i_row++) {
            const m_list = myArray[i_row].split(",");
            if (i_row % 2 == 0) {
                m_html += "<tr>"
            } else
                m_html += "<tr class=\"cur\">"

            for (var mCount = 0; mCount < m_list.length; mCount++) {
                if (isNumber(m_list[mCount])) {
                    if (m_list[mCount].length == 6)
                        statusNumber = true //设置涨幅
                }
                if (m_list[mCount + 1] == "" && m_list[mCount + 2] == "") {
                    m_html += "<td colspan =\"" + (m_list.length - mCount) + "\" >" + m_list[mCount] + "</td>"  //合并行
                    break;
                }
                if (mCount == mPrice && m_list[mCount] == "") {
                    break
                }
                m_html += "<td>" + m_list[mCount] + "</td>"
            }
            if (statusNumber) {
                m_html += "<td>" + dataInternet[m_list[mCode]] + "</td>"
                statusNumber = false
            }
            m_html += "</tr>"
        }
        var tb = document.getElementById('table'); //获取表格的dom节点
        tb.innerHTML = m_html
    }
</script>
<script>
    function isNumber(str) {
        var n = Number(str);
        if (!isNaN(n)) {
            return true
        } else {
            return false
        }
    }

</script>
<script>
    //数组分组
    function group(array, subNum) {
      let index = 0;
      let newArray = [];
      while(index < array.length) {
          newArray.push(array.slice(index, index += subNum));
      }
      return newArray;
  }
var Array = [1,2,3,4,5,6,7,8,9,10,11,12];`在这里插入代码片`
var groupArray = group(Array, 6);
</script>
<script>
    // 东方财富股票实时数据
    function codesRise(stocks, dataCvs, callback) {
        if (!stocks || stocks == false) {
            return null;
        }
        var m_data = []

        let stock = '';
        // console.log('stocks='+stocks);
        //获取股票代码
        var groupArray = group(stocks, 20);
        for(let i = 0; i < groupArray.length; i++){
            eastmoney(groupArray[i])
        }

        function eastmoney(stocks) {
            for (let i = 0; i < stocks.length; i++) {
                // if(stocks[i]=='000721'){
                //    console.log(stocks[i]);
                //    status = 1;
                // }
                if (stocks[i].slice(0, 1) == 6) {
                    // stocks[i]='1.'+stocks[i]+'%2C';
                    stock = stock + '1.' + stocks[i] + '%2C';
                } else {
                    // stocks[i]='0.'+stocks[i]+'%2C';
                    stock = stock + '0.' + stocks[i] + '%2C';
                }
            }

            $.ajax({
                url: 'https://push2.eastmoney.com/api/qt/ulist/get?fltt=1&invt=2&cb=jQuery351010838368397660503_1675494557241&fields=f3%2Cf12&secids=' + stock + '&ut=fa5fd1943c7b386f172d6893dbfba10b&pn=1&np=1&pz=20&wbp2u=%7C0%7C0%7C0%7Cweb&_=1675494557502',
                type: 'POST',
                async: true,
                dataType: 'text',
                // contentType: 'application/json; charset=UTF-8',
                success: function (data) {
                    var regex3 = /\{.*\}/;  // {} 花括号，大括号
                    // res.send(JSON.stringify(body.match(regex3)));// JSON格式化
                    data = data.match(regex3)[0];
                    // console.log(data);
                    var data = eval('(' + data + ')')['data']['diff'];//json格式化数据
                    //处理数据
                    let json = {};
                    for (let i = 0; i < data.length; i++) {
                        let float = (data[i]['f3'] / 100).toFixed(2);
                        json[data[i]['f12']] = float;
                    }
                    callback(dataCvs, json);
                },
                error: function (msg) {
                    console.log(msg);
                }
            })
        }


    };
</script>

<body>
    <div class="table-one">
        <table id="table" cellspacing="0">
        </table>
    </div>
</body>

</html>